{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7fea3aef-a900-41ef-bd14-0accb6de5565",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fa8bb98c-e747-41be-9a24-6c65d1ea1cb8",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from IPython.core.interactiveshell import InteractiveShell\n",
    "InteractiveShell.ast_node_interactivity = \"all\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "42d21c3d-a256-4ca4-94db-33a85f5ff0f4",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "#warnings.filterwarnings(action, message='', category=Warning, module='', lineno=0, append=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4ec9913-5d4d-487f-bbf8-226844ffd186",
   "metadata": {},
   "source": [
    "## **Chapter3 The NumPy Library**"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30049c82-ae88-4fea-82e8-afddbd6aad77",
   "metadata": {},
   "source": [
    "The NumPy library is based on one main object: `ndarray` (which stands for N-dimensional array). This object is a multidimensional, homogeneous array with a predetermined number of items: homogeneous because virtually all the items in it are of the same type and the same size.\n",
    "\n",
    "each ndarray is associated with only one type of dtype.\n",
    "The number of the dimensions and items in an array is defined by its shape, a tuple of N-positive integers that specifies the size for each dimension. The dimensions are defined as axes and the number of axes as rank."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37c289ba-b488-4d12-a55b-22b80db23e96",
   "metadata": {},
   "source": [
    "- Create an Array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d47382f9-5f1e-471a-a178-289e5cfd9353",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([1, 2, 3])\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8e0ecb81-af33-42a1-b47a-b5e5c80eb9b1",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array([[1, 2, 3],[4, 5, 6]]) #create through a list or sequence of lists as arguments to the array() function.\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "362bba75-916b-4273-b0f1-fdc4918cd7df",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = np.array(((1, 2, 3),(4, 5, 6))) #The array() function, in addition to lists, can accept tuples and sequences of tuples.\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c320ff9c-0db9-48f1-a5d8-9de045ee69ed",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6],\n",
       "       [7, 8, 9]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e = np.array([(1, 2, 3), [4, 5, 6], (7, 8, 9)]) #It can also accept sequences of tuples and interconnected lists.\n",
    "e"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5350848-2be3-45d4-bea3-bf094b7ce48b",
   "metadata": {},
   "source": [
    "- type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0bd6a3d3-7c25-493f-a37c-fe6c3c7d4e95",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "type(a)\n",
    "print(type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "87794675-f57e-49d0-ac02-991d5ad5c6ea",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('int64')"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "22fef51b-1d0a-46bd-8c5c-8004c4a8986f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.3, 2.4],\n",
       "       [0.3, 4.1]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "(2, 2)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = np.array([[1.3, 2.4],[0.3, 4.1]])\n",
    "b\n",
    "b.ndim\n",
    "b.size\n",
    "b.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50465469-8ce6-4a45-b024-a29e9317bf46",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Quantitative_Finance_python",
   "language": "python",
   "name": "quantitative_finance_python"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
